package de.jmda.gen.java.impl;

import static org.junit.Assert.assertTrue;

import org.apache.log4j.Logger;
import org.junit.Test;

import de.jmda.gen.GeneratorException;
import de.jmda.gen.LineIndenter;
import de.jmda.gen.impl.DefaultCompoundGenerator;
import de.jmda.gen.impl.DefaultGenerator;

public class JUT_DefaultCompoundGenerator
{
	private final static Logger LOGGER =
      Logger.getLogger(JUT_DefaultCompoundGenerator.class);

	@Test
	public void testDefaultCompoundGenerator() throws GeneratorException
	{
		String input1 = "input1";
		String input2 = "input2";

		DefaultCompoundGenerator generator = new DefaultCompoundGenerator();
		
		DefaultGenerator generatorComponent1 = new DefaultGenerator(input1);
		DefaultGenerator generatorComponent2 = new DefaultGenerator(input2);
		
		generator.addGeneratorComponent(generatorComponent1);
		generator.addGeneratorComponent(generatorComponent2);

		StringBuffer generated = generator.generate();

		LOGGER.debug("generated [" + generated + "]");

		assertTrue(
				"unexpected compound generation [" + generated + "]",
				(input1 + input2).contentEquals(generated));
	}

	@Test
	public void testNestedIndentation()
			throws GeneratorException
	{
		DefaultCompoundGenerator generator = new DefaultCompoundGenerator();
		
		DefaultGenerator generatorComponent = new DefaultGenerator("xxx");
		
		generator.addGeneratorComponent(generatorComponent);

		generatorComponent.setLineIndenter(new LineIndenter("2", 3));
		generator.setLineIndenter(new LineIndenter("1", 3));

		StringBuffer generated = generator.generate();

		LOGGER.debug("generated [" + generated + "]");

		assertTrue(
				"unexpected compound generation [" + generated + "]",
				"111222xxx".contentEquals(generated));
	}
}